package com.ax.location.flutter_location_plugin;

import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;

import androidx.annotation.NonNull;

import java.util.HashMap;
import java.util.Map;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;


/** FlutterLocationPlugin */
public class FlutterLocationPlugin implements FlutterPlugin, MethodCallHandler {
  private static final String TAG = "FlutterLocationPlugin";

  private final Registrar registrar;

  private FlutterLocationPlugin(Registrar registrar) {
    this.registrar = registrar;
  }

  @Override
  public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
    final MethodChannel channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "flutter_location_plugin");
    channel.setMethodCallHandler(new FlutterLocationPlugin(registrar));
  }

  public static void registerWith(Registrar registrar) {
    final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_location_plugin");
    channel.setMethodCallHandler(new FlutterLocationPlugin(registrar));
  }

  @Override
  public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
    if (call.method.equals("getPlatformVersion")) {
      result.success("Android " + android.os.Build.VERSION.RELEASE);
    }else if(call.method.equals("getLocation")){
      getLocation(result);
    } else{
      result.notImplemented();
    }
  }

  @Override
  public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
  }

 private void getLocation( @NonNull Result result){
   Map<String, Object> data = new HashMap<>();
   data.put("city","上海");
   System.out.print(registrar.context());
   result.success(data);
 }

}
